﻿'Created By : Ahmad Abdan
'Date : 09/06/2010
'Subject : Database Table Field Class

Public Class DBParentStoredProcedureClass

    'FieldsArrayList : Store TabelFields for all stored Procedure that will passed to SP
    'SPName : Stored Procedure Name in the DataBase
    'DBConnection : Object that will intract Directly With Database
    Protected FieldsArrayList As ArrayList
    Protected SPName As String
    Protected DBConnection As DBConnectionClass

    'Initialize DBConnection Object 
    Public Sub New()
        DBConnection = New DBConnectionClass
    End Sub

    'SqlQueryType : is Enumeration of all availabe operation that 
    '               can be Accomplished through DBConnection Object 

    'ExecuteNonQuery : Performs commands that change the database but do not return a 
    '                  specific value, including adding and deleting items from a database. 
    '                  The ExecuteNonQuery method returns the number of rows affected by the command.
    'ExecuteScalar   : Performs query commands that return a single value, such as counting the number of records in a table.
    'FillDataset     : Return the select Statment result from Databse as a Dataset
    'ExecuteReader   : Reads records sequentially from the database.
    'ExecuteXmlReader: Return the select Statment result from Databse as a XmlReader

    Public Enum SqlQueryType
        ExecuteNonQuery
        FillDataset
        ExecuteReader
        ExecuteScalar
        ExecuteXmlReader
    End Enum

    'QueryDatabase Function call the approbrite function from DBConnection Class
    '   based on the sended QueryType Operation
    Protected Overridable Function QueryDatabase(ByVal QueryType As SqlQueryType) As Object
        'If FieldsArrayList.Count > 0 Then0


        'isolation by hassan 05-03-2008
        'Dim sql As String = "set TransAction isolation level SNAPSHOT"
        'Dim conn As New DBConnectionGeneral
        'conn.ExecuteSQL(sql)

        'Dim ds As New DataSet
        'ds = conn.ExecuteSQL("dbcc useroptions")
        'x = ds.Tables(0).Rows(12)("Value")
        'isolation


        Select Case QueryType
            Case SqlQueryType.ExecuteNonQuery
                Return DBConnection.ExecuteNonQuery(FieldsArrayList, SPName)
            Case SqlQueryType.ExecuteScalar
                Return DBConnection.ExecuteScalar(FieldsArrayList, SPName)
            Case SqlQueryType.FillDataset
                Return DBConnection.FillDataset(FieldsArrayList, SPName)
            Case SqlQueryType.ExecuteReader
                Return DBConnection.ExecuteReader(FieldsArrayList, SPName)
            Case SqlQueryType.ExecuteXmlReader
                Return DBConnection.ExecuteXmlReader(FieldsArrayList, SPName)
        End Select
        'End If
        'conn = Nothing
        Return Nothing
    End Function

    'Set Or Get Stored Procedure Name
    Public Property StoredProcedureName() As String
        Get
            Return SPName
        End Get
        Set(ByVal Value As String)
            SPName = Value
        End Set
    End Property


End Class

